<template>
  <div class="rank-container">
    <!-- 标题 -->
    <div class="scene-title">
      <p>景区排行</p>
      <img src="../../images/dataScreen-title.png" alt="暂无图片" />
    </div>
    <!-- 图表 -->
    <div ref="rankRef" class="scene-echart"></div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from "vue";
import * as echarts from "echarts";

let rankRef = ref();
onMounted(() => {
  const myEchart = echarts.init(rankRef.value);
  myEchart.setOption({
    title: {
      text: "景区排行", // 主标题
      left: "45%", // 左侧距离
      textStyle: {
        // 标题样式
        color: "white",
        fontSize: 18,
      },
      subtext: "各大景区", // 子标题
      subtextStyle: {
        color: "gary",
      },
    },
    grid: {
      left: 20,
      right: 20,
      bottom: 30,
    },
    xAxis: {
      // type: "category",
      axisLine: {
        // 坐标轴
        show: true,
      },
      axisLabel: {
        color: "white",
        fontSize: 16,
      },
      splitLine: {
        // 分割线
        show: false,
      },
      data: ["景区一", "景区二", "景区三", "景区四", "景区五"],
    },
    yAxis: {
      // type: "value",
      axisLine: {
        // 坐标轴
        show: true,
      },
      axisLabel: {
        color: "white",
        fontSize: 16,
      },
      splitLine: {
        // 分割线
        show: false,
      },
    },
    series: [
      {
        type: "bar",
        data: [1, 4, 7, 8, 3],
        label: {
          show: true, // 是否展示文字
          color: "white",
          fontSize: 16,
        },
        // 是否显示背景颜色
        showBackground: true,
        // 背景颜色样式
        backgroundStyle: {
          color: "brown",
        },
        itemStyle: {
          color: (params: any) => {
            let color = ["orange", "yellow", "green", "blue", "violet"];
            return color[params.dataIndex];
          },
          borderRadius: 10,
        },
      },
      {
        type: "bar",
        data: [
          [0, 1],
          [1, 4],
          [2, 7],
          [3, 8],
          [4, 3],
        ],
        label: {
          show: true, // 是否展示文字
          color: "white",
          fontSize: 16,
        },
        // 是否显示背景颜色
        showBackground: true,
        // 背景颜色样式
        backgroundStyle: {
          color: "brown",
        },
        itemStyle: {
          color: (params: any) => {
            let color = ["orange", "yellow", "green", "blue", "violet"];
            return color[params.dataIndex];
          },
          borderRadius: 10,
        },
      },
      {
        type: "line",
        data: [1, 4, 7, 8, 3],
        lineStyle: {
          color: "violet",
          type: "dashed",
          width: 3,
        },
        smooth: true,
      },
    ],
    tooltip: {
      backgroundColor: "yellow",
    },
  });
});
</script>

<style scoped lang="scss">
.rank-container {
  flex: 1.3;
  width: 100%;
  background: url("../../images/dataScreen-main-rt.png") no-repeat;
  background-size: 100% 100%;
  margin-top: 14px;
  .scene-title {
    color: white;
    font-size: 20px;
  }
  .scene-echart {
    width: 100%;
    height: calc(100% - 40px);
  }
}
</style>
